﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace AlbonWeb.Manager.BulletinManager
{
    public partial class BulletinAdd : System.Web.UI.Page
    {
        private readonly BLL.BulletinBLL bulletinbll = new BLL.BulletinBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ViewState["Back"] = Request.UrlReferrer.ToString();
                if (Request["id"] != null)
                {
                    initData(Request["id"].ToString());
                }
            }
        }

        //初始化要修改的数据
        private void initData(string id)
        {
            DataTable dt= bulletinbll.getBulletinByID(id);
            tbTitle.Text = dt.Rows[0]["title"].ToString();
            tbContent.Text = dt.Rows[0]["content"].ToString();
            needCheck.Checked = !bool.Parse(dt.Rows[0]["active"].ToString());
        }

        //添加信息
        protected void addMessage_Click(object sender, EventArgs e)
        {
            Albon.Model.BulletinMessage bulletin = new Albon.Model.BulletinMessage();
            bulletin.ID = 0;
            if (Request["id"]!= null)
            {
                bulletin.ID = int.Parse(Request["id"].ToString());
            }
            bulletin.title = tbTitle.Text.Trim();
            bulletin.content = tbContent.Text;
            bulletin.active = !needCheck.Checked;
            bulletinbll.Add(bulletin);
            Response.Redirect(ViewState["Back"].ToString());
        }
    }
}